﻿using Topshelf;
using Wolfpack.Periscope.Core;
using Wolfpack.Periscope.Core.Interfaces;
using Wolfpack.Periscope.Core.Plugins;

namespace Wolfpack.Periscope.Hosts
{
    class Program
    {
        static void Main(string[] args)
        {
            HostFactory.Run(
                config =>
                {
                    config.SetDisplayName("Wolfpack Periscope");
                    config.SetServiceName("Periscope");
                    config.SetDescription("Wolfpack Periscope Dashboard Service");

                    string username;
                    string password;

                    //if (CmdLine.Value(CmdLine.SwitchNames.Username, out username) &&
                    //    CmdLine.Value(CmdLine.SwitchNames.Password, out password))
                    //{
                    //    Logger.Debug("Running As: {0}", username);
                    //    config.RunAs(username, password);
                    //}

                    config.Service<IDashboard>(configurator => 
                    {
                        configurator.ConstructUsing(factory =>
                        {
                            var bootstrapper = new DashboardBootstrapper();
                            var dashboard = bootstrapper.Configure(infrastructure =>
                            {
                                infrastructure.RegisterPlugin<SignalRPlugin>();
                                infrastructure.RegisterPlugin<NancyFxSelfHostPlugin>();
                                //infrastructure.RegisterPlugin<RotatingPanelSelectorPlugin>();
                                infrastructure.RegisterPlugin<PanelRefreshPlugin>();
                                //infrastructure.RegisterPlugin<BootstrapWidgetsPlugin>();
                            });

                            return dashboard;
                        });

                        configurator.WhenStarted(s => s.Start());
                        configurator.WhenStopped(s => s.Dispose());
                    });
                });
        }
    }
}
